export const crudOptions = (vm) => {
  return {
    pageOptions: {
      compact: true
    },
    options: {
      tableType: 'vxe-table',
      rowKey: false,
      width: '100%',
      height: '100%' // 表格高度100%, 使用toolbar必须设置
    },
    rowHandle: {
      width: 140,
      view: {
        thin: true,
        text: '',
        disabled () {
          return !vm.hasPermissions('Retrieve')
        }
      },
      edit: {
        thin: true,
        text: '',
        disabled () {
          return !vm.hasPermissions('Update')
        }
      },
      remove: {
        thin: true,
        text: '',
        disabled () {
          return !vm.hasPermissions('Delete')
        }
      }
    },
    viewOptions: {
      componentType: 'form'
    },
    formOptions: {
      type: 'drawer',
      draggable: false, // 关闭拖拽
      fullscreen: false, // 关闭全屏功能
      defaultSpan: 24, // 默认的表单 span
      size: '900px',
      appendToBody: true // 配置表单是否插入至 body 元素上
    },
    indexRow: { // 或者直接传true,不显示title，不居中
      title: '序号',
      align: 'center',
      width: 100
    },
    columns: [
      {
        title: 'ID',
        key: 'id',
        width: 90,
        disabled: true,
        form: {
          disabled: true
        }
      },
      {
        title: '套餐名称',
        key: 'name',
        search: {
          disabled: false
        },
        width: 160,
        type: 'input',
        form: {
          rules: [ // 表单校验规则
            { required: true, message: '套餐名称不能为空' }
          ],
          component: {
            placeholder: '请输入套餐名称'
          },
          itemProps: {
            class: { yxtInput: true }
          }
        }
      }, {
        title: '套餐说明',
        key: 'description',
        search: {
          disabled: true
        },
        minWidth: 160,
        type: 'textarea',
        form: {
          rules: [ // 表单校验规则
            { required: true, message: '套餐说明不能为空' }
          ],
          component: {
            placeholder: '请输入套餐说明',
            showWordLimit: true,
            maxlength: '2000',
            props: {
              type: 'textarea'
            },
            autosize: {
              minRows: 5, maxRows: 10
            }
          },
          itemProps: {
            class: { yxtInput: true }
          }
        }
      },
      {
        title: '套餐价格',
        key: 'package_price',
        minWidth: 120,
        rowSlot: true,
        form: {
          component: {
            span: 24
          },
          rules: [ // 表单校验规则
            { required: true, message: '套餐价格不能为空' }
          ],
          itemProps: {
            class: { yxtInput: true }
          },
          slot: true
        }
      }, {
        title: '套餐状态',
        key: 'status',
        search: {
          disabled: false
        },
        type: 'radio',
        minWidth: 100,
        dict: {
          data: vm.dictionary('button_status_bool')
        },
        form: {
          value: true,
          component: {
            placeholder: '请选择套餐状态',
            span: 12
          },
          rules: [ // 表单校验规则
            { required: true, message: '套餐状态必填项' }
          ],
          itemProps: {
            class: { yxtInput: true }
          }
        },
        component: { props: { color: 'auto' } }
      }, {
        title: '等级',
        key: 'sort',
        minWidth: 100,
        type: 'number',
        form: {
          value: 1,
          component: {
            span: 12
          },
          rules: [ // 表单校验规则
            { required: true, message: '排序必填项' }
          ],
          itemProps: {
            class: { yxtInput: true }
          }
        }
      },
      {
        title: '套餐功能',
        key: 'package_features',
        type: 'card-select',
        search: {
          disabled: true
        },
        show: false,
        dict: {
          cache: false,
          url: '/api/tenant/package_features/get_all_data/',
          value: 'id', // 数据字典中value字段的属性名
          label: 'name' // 数据字典中label字段的属性名
        },
        minWidth: 120,
        form: {
          value: [],
          component: {
            placeholder: '请选择套餐功能',
            props: {
              fields: {
                name: 'name', // 名称
                content: 'description', // 内容描述字段
                required: 'is_required', // 必选字段
                icon: 'icon', // 图标字段
                group: 'category' // 分组字段
              }
            }
          },
          rules: [ // 表单校验规则
            { required: true, message: '必填项' }
          ],
          itemProps: {
            class: { yxtInput: true }
          }
        },
        component: { props: { color: 'auto' } }
      }
    ].concat(vm.commonEndColumns({
      update_datetime: { showTable: false },
      description: { showTable: false, showForm: false }
    }))
  }
}
